package top.chj.day17.exam;

import org.junit.Test;

/**
 * @Auther:小陈的Java
 * 获取一个字符串在另一个字符串中出现的次数。比如：获取“ ab”在 在 “abcdabcdabcd” 中出现的次数
 */
public class Test5 {
    public int Count(String Str1,String Str2){
        int s1length = Str1.length();//12
        int s2length = Str2.length();//2
        int count = 0;
        int index = 0;
        if (s1length >= s2length){
            while ((index = Str1.indexOf(Str2,index)) != -1){
                count++;
                index += s2length;
            }
            return count;
        }else {
            return 0;
        }
    }
    @Test
    public void testCount(){
        String Str1 = "abcdabcdabcd";
        String Str2 = "ab";
        int count = Count(Str1,Str2);
        System.out.println(count);
    }
}
